﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;

public class LoginBLL
{
    public LoginProperty UserLogin(LoginProperty StudentUser)
    {
        string connection = WebConfigurationManager.ConnectionStrings["UCNLinkDB"].ConnectionString;

        MySqlConnection conn = new MySqlConnection(connection);
        MySqlCommand comm = new MySqlCommand("SELECT tblStudent.ID, tblStudent.studName, tblStudent.studMail, tblStudent.studPhoneNo, tblStudent.studPassword, tblStudent.SubEducationID, tblStudent.studTerm FROM tblStudent WHERE tblStudent.studPassword = @studPassword AND tblStudent.ID = @ID", conn);
        
        comm.Parameters.Add("@studPassword", MySqlDbType.VarChar, 20);
        comm.Parameters["@studPassword"].Value = StudentUser.Password;
        comm.Parameters.Add("@ID", MySqlDbType.VarChar, 15);
        comm.Parameters["@ID"].Value = StudentUser.Id;

        conn.Open();

        comm.Connection = conn;

        LoginProperty objUser = new LoginProperty();

        MySqlDataReader reader = comm.ExecuteReader();

        if (reader.HasRows)
        {
            reader.Read();

            objUser.StudentName = reader["studName"].ToString();
            objUser.Id = reader["ID"].ToString();
            objUser.StudentMail = reader["studMail"].ToString();
            objUser.Password = reader["studPassword"].ToString();
            objUser.StudentPhoneNo = reader["studPhoneNo"].ToString();
            objUser.SubEducationId = Convert.ToInt32(reader["SubEducationID"].ToString());
            objUser.StudTerm = reader["studTerm"].ToString();

            reader.Close();
        }
        comm.Dispose();
        conn.Close();
        return objUser;
    }
	public LoginBLL()
	{
        
	}
}